import Taro, {Component, Config} from '@tarojs/taro';
import {View} from '@tarojs/components';
import './index.scss';
import {AtButton, AtIcon} from 'taro-ui';
import HxPage from '../../components/hxPage/hxPage';
import HxRewardList from '../../components/hxRewardList/hxRewardList';

export default class ChargeResult extends Component {
    constructor() {
        super(...arguments);
        this.state = {
            payItem: '',
            money: '',
            payflag: '',
            rewardList: [],
        };
    }

    config: Config = {
        // navigationBarTitleText: '一卡通充值结果'
        navigationBarTitleText: ''
    };

    componentWillMount() {
        if (this.$router.params.payItem !== undefined && this.$router.params.rewardList !== undefined) {
            this.setState({
                payItem: this.$router.params.payItem,
                money: this.$router.params.money,
                payflag: this.$router.params.payflag,
                rewardList: JSON.parse(this.$router.params.rewardList),
            });
        }
    }

    goNext() {
        Taro.navigateBack({
            delta: this.state['payItem'] === '0' ? 3 : 2
        });
    }

    render() {
        // @ts-ignore
        const {payItem, money, payflag, rewardList} = this.state;
        return (
            <HxPage>
                <View className='charge_result'>
                    <View className='charge_result_item'>
                        <AtIcon value={payflag === '1' ? 'check-circle' : 'close-circle'} size='120' color='#b71120'/>
                    </View>
                    <View className='charge_result_item'>
                        {payItem === '0' ? '充值' : '缴费'}金额：<View
                        className='charge_result_item_money'>{Number(money).toFixed(2)}</View>元
                    </View>
                    <View className='charge_result_item'>
                        {payflag === '1' ? '恭喜您，' + (payItem === '0' ? '充值' : '缴费') + '成功' : '很遗憾，' + (payItem === '0' ? '充值' : '缴费') + '失败'}
                    </View>
                </View>
                <HxRewardList rewardList={rewardList}/>
                <AtButton className='hxButton' onClick={this.goNext.bind(this)}>返回</AtButton>
            </HxPage>
        );
    }
}
